package code.c03_stackQueue.linkStack;

/**
 * @author thinkpad - 83start
 * @version v1.0
 * @create 2022/10/2 21:53
 * @package code.c03_stackQueue.linkStack
 * @description 设计一个算法，利用栈的基本运算将一个整数链栈中的所有元素逆置
 */

public class Exam_3_8 {
    final static int MAX_SIZE = 100;

    public static LinkStackClass<Integer> reverse(LinkStackClass<Integer> st) {
        int[] a = new int[MAX_SIZE];
        int i = 0;
        while (!st.empty()) {
            a[i] = st.pop();
            i++;
        }
        for (int j = 0; j < i; j++) {
            st.push(a[j]);
        }

        return st;
    }

    public static void main(String[] args) {
        LinkStackClass<Integer> st = new LinkStackClass<>();
        int[] a = {1, 2, 3, 3, 1, 4};

        for (int i = 0; i < a.length; i++) {
            st.push(a[i]);
        }

//        String op1 = "";
//        while (!st.empty()) {
//            op1 += st.pop() + " ";
//        }
//        System.out.println(op1);

        LinkStackClass<Integer> reverseSt = reverse(st);

        String op2 = "";
        while (!reverseSt.empty()) {
            op2 += reverseSt.pop() + " ";
        }
        System.out.println(op2);
    }
}
